package engine.query;

import compiler.absyn.*;

import storage.record.Schema;


public class SelectPlan implements Plan {
	private Plan p;
	private Predicate pred;

	public SelectPlan(Plan p, Predicate pred) {
		this.p = p;
		this.pred = pred;
	}

	public Scan open() {
		Scan s = p.open();
		return new SelectScan(s, pred);
	}

	
	public int blocksAccessed() {
		return p.blocksAccessed();
	}

	
	public int recordsOutput() {
		return p.recordsOutput() / pred.reductionFactor(p);
	}

	
	public int distinctValues(String fldname) {
		if (pred.equatesWithConstant(fldname) != null)
			return 1;
		else
			return Math.min(p.distinctValues(fldname),
							recordsOutput());
	}

	
	public Schema schema() {
		return p.schema();
	}
}
